package com.yj.oa.mapper;

import com.yj.oa.entity.system.UserRelationship;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

/**
 * Copyright 2017 (C) Yunjian-VC
 * Created on : 2017/12/1
 * Author     : Unbelievable9
 **/
@Repository
@Mapper
public interface UserRelationshipMapper {

    @Insert("INSERT INTO user_relationship (ym_user_id, ym_user_phone, oa_user_id, oa_username, oa_user_token, create_time) " +
            "VALUES(#{item.ym_user_id}, #{item.ym_user_phone}, #{item.oa_user_id}, #{item.oa_username}, #{item.oa_user_token}, now())")
    void insert(@Param("item") UserRelationship item);

    @Select("SELECT * FROM user_relationship WHERE ym_user_id = #{id} LIMIT 1")
    UserRelationship getByYmUserID(@Param("id") Integer id);

    @Select("SELECT * FROM user_relationship WHERE oa_user_id = #{id} LIMIT 1")
    UserRelationship getByOAUserID(@Param("id") String id);

    @Select("SELECT * FROM user_relationship WHERE oa_username = #{name} LIMIT 1")
    UserRelationship getByOAUsername(@Param("name") String name);

    @Select("SELECT oa_user_id FROM user_relationship WHERE oa_user_token = #{token} LIMIT 1")
    String getOAUserIDByToken(@Param("token") String token);

    @Select("SELECT oa_user_token FROM user_relationship WHERE oa_user_id = #{user_id} LIMIT 1")
    String getTokenByUserID(@Param("user_id") String user_id);
}
